package com.example.blogsystem.demos.utils;

import org.springframework.util.DigestUtils;

import java.util.UUID;

public class UUIDUtil {
    public static String encry(String password){
        String salt = UUID.randomUUID().toString().replace("-", "");
        String securityPassword = DigestUtils.md5DigestAsHex((salt + password).getBytes());
        return salt + securityPassword;
    }

    public static boolean verify(String inputPassword, String sqlPassword){
        if (sqlPassword ==null || sqlPassword.length()!=64){
            return false;
        }
        String salt = sqlPassword.substring(0,32);

        String securityPassword = DigestUtils.md5DigestAsHex((salt+inputPassword).getBytes());
        return (salt+securityPassword).equals(sqlPassword);
    }
}
